import org.junit.jupiter.api.Test;

import java.io.FileNotFoundException;
import java.util.Arrays;

public class test {
    @Test
    public void test() {
        String[] background = {"https://example.com/im,age1.jpg", "https://example.com/image2.jpg"};

        // 处理边界条件
        if (background == null || background.length == 0) {
            System.out.println("Background array is empty or null.");
            return;
        }

        // 使用流操作并将结果收集到新的数组中
        String[] processedBackground = Arrays.stream(background)
                .filter(s -> s != null) // 过滤掉 null 值
                .map(s -> s.replace(",", "%2C")) // 替换逗号
                .toArray(String[]::new);

        // 打印处理后的背景图片链接
        for (String s : processedBackground) {
            System.out.println(s);
        }

        // 将处理后的数组转换为逗号分隔的字符串
        String backgroundString = String.join(",", processedBackground);
        System.out.println(backgroundString);
    }
}
